import unittest
import requests
from IHRM import app
from IHRM.api.login import loginAPI


class Testlogin(unittest.TestCase):
    def setUp(self):
        self.login_api = loginAPI()
        #self.session = requests.Session()

    #def tearDown(self):
        #if self.session:
            #self.session.close()
    #登录成功
    def test01(self):
        port = self.login_api.login({"mobile":"13800000002","password":"929itheima.CN032@.20250212"})
        print(port.json())
        self.assertEqual(200, port.status_code)
        self.assertEqual(True, port.json().get("success"))
        self.assertEqual(10000, port.json().get("code"))
        self.assertIn("操作成功", port.json().get("message"))

        #提取token信息
        app.TOKEN = "Bearer " + port.json().get("data")
        print(app.TOKEN)
        #把提取的token信息返回给app文件下的TOKEN
        app.headers_data["Authorization"] = app.TOKEN
        print(app.headers_data["Authorization"])